package com.j283_5.wisdom_park.controller.article_management;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.j283_5.wisdom_park.common.result.ResultData;
import com.j283_5.wisdom_park.pojo.Article;
import com.j283_5.wisdom_park.pojo.Visitors;
import com.j283_5.wisdom_park.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 *
 * @author laoda
 * @since 2022-04-28
 */
@RestController
@RequestMapping("/article")
@Api(value = "文章发布管理",tags = "文章发布管理",produces="冯弋舟")
public class ArticleController {

    @Resource
    private ArticleService articleService;

    /**
     * 多条件查询文章
     * @return
     */
    @RequestMapping(value = "/findArticle" , method = RequestMethod.GET)
    @ApiOperation(value = "多条件查询文章",notes = "多条件查询文章（分页）",produces="冯弋舟", response = ResultData.class)
    public ResultData findArticle(@Param("page") Page<Visitors> page, @Param("article") Article article){
        Map<String, Object> map = articleService.findArticle(article, (int) page.getCurrent(), (int) page.getSize());
        return ResultData.ok().data(map);
    }

    /**
     * 查看文章详情
     * @return
     */
    @RequestMapping(value = "/findArticleInfo" , method = RequestMethod.GET)
    @ApiOperation(value = "查看文章详情",notes = "查看文章详情",produces="冯弋舟", response = ResultData.class)
    public ResultData updateArticle(@Param("page") Page<Visitors> page, @Param("article") Article article){
        Map<String, Object> map = articleService.findArticle(article, (int) page.getCurrent(), (int) page.getSize());
//        Map<String, Object> map1 = articleService.findInsert();
//        map.put("insertData",map1);
        return ResultData.ok().data(map);
    }


    /**
     * 删除文章信息
     * @return
     */
    @RequestMapping(value = "/deleteArticle" , method = RequestMethod.POST)
    @ApiOperation(value = "删除文章信息",notes = "删除文章信息",produces="冯弋舟", response = ResultData.class)
    public ResultData DeleteArticle(@RequestBody List<Integer> listArticle){
        return articleService.deleteArticle(listArticle);
    }

    /**
     * 新增文章信息
     * @return
     */
    @RequestMapping(value = "/insertArticle" , method = RequestMethod.POST)
    @ApiOperation(value = "新增文章信息",notes = "新增文章信息",produces="冯弋舟", response = ResultData.class)
    public ResultData InsertArticle(@Param("article") Article article){

        return articleService.insertArticle(article);
    }


}

